-
Notifications
You must be signed in to change notification settings - Fork 4
fix: adjust sponsor global quantity metafield initial value #774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Tomás Castillo <[email protected]>
📝 WalkthroughWalkthroughDefault sponsor form meta_fields were changed from a pre-populated single empty field to an empty array across reducers, dialogs, and UI; AdditionalInputList now manages draft items with per-item Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
…, adjust test Signed-off-by: Tomás Castillo <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
src/reducers/sponsors/sponsor-customized-form-items-list-reducer.js (1)
128-138:⚠️ Potential issue | 🟡 MinorInconsistent fallback meta_fields structure.
The fallback meta_fields object when
item.meta_fields.length === 0doesn't includeminimum_quantityandmaximum_quantity, unlike theDEFAULT_ITEM_ENTITYdefinition. This could cause inconsistent state shapes.Proposed fix
: [ { name: "", type: "Text", is_required: false, + minimum_quantity: 0, + maximum_quantity: 0, values: [] } ]src/reducers/sponsors/sponsor-form-items-list-reducer.js (1)
115-125:⚠️ Potential issue | 🟡 MinorInconsistent fallback meta_fields structure.
Same issue as in
sponsor-customized-form-items-list-reducer.js— the fallback meta_fields whenitem.meta_fields.length === 0is missingminimum_quantityandmaximum_quantity.Proposed fix
: [ { name: "", type: "Text", is_required: false, + minimum_quantity: 0, + maximum_quantity: 0, values: [] } ]src/reducers/sponsors/sponsor-forms-list-reducer.js (1)
136-146:⚠️ Potential issue | 🟡 MinorInconsistent fallback meta_fields structure.
Same pattern as other reducers — the fallback meta_fields when
form.meta_fields.length === 0is missingminimum_quantityandmaximum_quantity. Consider adding them for consistent state shape.Proposed fix
: [ { name: "", type: "Text", is_required: false, + minimum_quantity: 0, + maximum_quantity: 0, values: [] } ]src/reducers/sponsors_inventory/inventory-item-reducer.js (1)
29-50:⚠️ Potential issue | 🟠 MajorAvoid shared default meta_fields object across resets.
DEFAULT_ENTITYnow contains a nested object/array, but reducer paths use shallow copies, so later mutations (e.g., updatingmetaField.values) can leak into the default and affect new forms. Use a factory function to create fresh defaults each time.✅ Proposed fix
-export const DEFAULT_ENTITY = { +const createDefaultMetaField = () => ({ + name: "", + type: "Text", + is_required: false, + minimum_quantity: 0, + maximum_quantity: 0, + values: [] +}); + +export const createDefaultEntity = () => ({ id: 0, code: "", name: "", description: "", default_quantity: 0, quantity_limit_per_show: 0, quantity_limit_per_sponsor: 0, early_bird_rate: 0, standard_rate: 0, onsite_rate: 0, images: [], - meta_fields: [ - { - name: "", - type: "Text", - is_required: false, - minimum_quantity: 0, - maximum_quantity: 0, - values: [] - } - ] -}; + meta_fields: [createDefaultMetaField()] +}); -const DEFAULT_STATE = { - entity: DEFAULT_ENTITY, +const DEFAULT_STATE = { + entity: createDefaultEntity(), errors: {} };Then update usages (e.g., RESET/RECEIVE/ADDED/UPDATED) to spread
createDefaultEntity()instead ofDEFAULT_ENTITY.
🧹 Nitpick comments (1)
src/reducers/sponsors/__tests__/sponsor-form-items-list-reducer.test.js (1)
198-204: Test expectation aligns with reducer inconsistency.The expected
meta_fieldsin this test doesn't includeminimum_quantityandmaximum_quantity, which matches the current reducer fallback behavior. If you fix the reducer's fallback (as suggested in the reducer review), update this expectation accordingly.
Signed-off-by: Tomás Castillo <[email protected]>
93dd620 to
51c7fea
Compare
Signed-off-by: Tomás Castillo <[email protected]>
…ll cases Signed-off-by: Tomás Castillo <[email protected]>
Signed-off-by: Tomás Castillo <[email protected]>
Signed-off-by: Tomás Castillo <[email protected]>
Signed-off-by: Tomás Castillo <[email protected]>
smarcet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ref: https://app.clickup.com/t/86b8bdd54
Signed-off-by: Tomás Castillo [email protected]
Summary by CodeRabbit
Bug Fixes
Refactor